import { defineStore } from 'pinia'

export const userStore = defineStore('user', {
  state: () => {
    return {
      token: '',
      userInfo: {},
      notices: []
    }
  },
  actions: {
    setNotices(e) {
      this.notices = e
    },
    setToken(e) {
      this.token = e
      uni.setStorage({
        key: 'token',
        data: this.token,
        success: () => {
          console.log(this.token)
        }
      })
    },
    setUserInfo(e) {
      this.userInfo = e
    },
    updateUserAvatar(e) {
      this.userInfo.avatarURL = e
    },
    destroyToken() {
      this.token = ''
      this.userInfo = {}
    }
  },
  persist: {
    enabled: true
  }
})
